class Solution {
public:
    int findPeakElement(vector<int>& nums) {
        if (nums.size() == 1)
            return 0;
        if (nums.size() == 2)
        {
            if (nums[1] > nums[0])
                return 1;
            else
                return 0;
        }
        int left = 0;
        int right = nums.size() - 1;
        while (left < right)
        {
            int mid = left + (right - left + 1) / 2;
            if ((mid - 1 < 0 || nums[mid] > nums[mid - 1]) && (mid + 1 >= nums.size() || nums[mid] > nums[mid + 1]))
            {
                return mid;
            }
            else if (nums[mid] > nums[mid - 1])
            {
                left = mid;
            }
            else if (nums[mid] < nums[mid - 1])
            {
                right = mid - 1;
            }
        }
        return left;
    }
};